package cn.smbms.tools;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class BaseDao {
	public static Connection getConnection(){
		Connection connection=null;
		String driver=ConfigManager.getInstance().getValue("driver");
		String url=ConfigManager.getInstance().getValue("url");
		String user=ConfigManager.getInstance().getValue("username");
		String password=ConfigManager.getInstance().getValue("password");
		try {
			Class.forName(driver);
			connection=DriverManager.getConnection(url,user,password);
		} catch (Exception e) {
	
			e.printStackTrace();
		}
		return connection;
	}
	
	public static void close(Connection conn,PreparedStatement pstmt,ResultSet rs){
		try {
			if(conn!=null){
				conn.close();
			}
			if(pstmt!=null){
				pstmt.close();
			}
			if(rs!=null){
				rs.close();
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
